﻿// ParseLib - An open source library for natural language processing.
// Copyright (C) Kais Dukes, 2012. E-mail: kais@kaisdukes.com
// http://parselib.org

using System.Collections.Generic;

namespace ParseLib.Tagging
{
    public abstract class Tagset<T> : ITagset
    {
        private readonly IDictionary<string, T> _tags = new Dictionary<string, T>();

        public int Count
        {
            get { return _tags.Count; }
        }

        public T Build(string symbol)
        {
            // Existing tag?
            T tag;
            if (_tags.TryGetValue(symbol, out tag)) return tag;

            // New tag.
            var number = _tags.Count + 1;
            _tags.Add(symbol, tag = CreateTag(symbol, number));
            return tag;
        }

        protected abstract T CreateTag(string symbol, int number);
    }
}
